﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft Corp." file="AddSchedulerJobCmdlet.cs">
//   All rights reserved. See License.txt in the project root for license information.
// </copyright>
// 
// --------------------------------------------------------------------------------------------------------------------
namespace CloudBlitz.Powershell.Cmdlets
{
    using System;
    using System.Management.Automation;

    using HpcSchedulerManagement.DataContracts;

    [Cmdlet(VerbsCommon.Add, "SchedulerJob")]
    public class AddSchedulerJobCmdlet : HpcSchedulerCmdletBase
    {
        [Parameter(Mandatory = true)]
        [ValidateNotNull]
        public SchedulerJob Job { get; set; }

        protected override void ProcessRecord()
        {
            try
            {
                base.ProcessRecord();
                this.AddSchedulerJobProcess();
            }
            catch (Exception ex)
            {
                this.ThrowTerminatingError(this.HandleException(ex).Result);
            }
        }

        private void AddSchedulerJobProcess()
        {
            var jobId = this.CreateClient().CreateJob(this.Credentials.ClusterName, this.Job).Result;

            this.WriteObject(jobId);
        }
    }
}